﻿using MediatR;
using Microsoft.Extensions.Caching.Memory;
using QuartzServices.Application.BOM;
using QuartzServices.Application.SystemLog;
using QuartzServices.Domain.CommandHandlers.BOM;
using QuartzServices.Domain.CommandHandlers.BOM.Commands;
using QuartzServices.Domain.Core.Bus;
using QuartzServices.Domain.Core.Notifications;
using QuartzServices.Domain.Interfaces;
using QuartzServices.Infrastructure.Bus;
using QuartzServices.Infrastructure.Repository;
using QuartzServices.Infrastructure.UoW;

namespace QuartzServices.Web.Extensions
{
    public static class AutoInjectorSetup
    {
        public static void RegisterServices(IServiceCollection services) 
        {
            // 应用层
            services.AddScoped<ISystemLogApplication, SystemLogApplication>();
            services.AddScoped<IBlcSapLocationSyncApplication, BlcSapLocationSyncApplication>();

            // 命令总线
            services.AddScoped<IMediatorHandler, InMemoryBus>();

            // 领域命令
            services.AddScoped<IRequestHandler<BlcSapLocationSyncCommand, bool>, BlcSapLocationSyncHandler>();

            // 领域通知
            services.AddScoped<INotificationHandler<DomainNotification>, DomainNotificationHandler>();

            services.AddSingleton<IMemoryCache>(factory =>
            {
                return new MemoryCache(new MemoryCacheOptions());
            });

            // 基础设施层
            services.AddScoped<IJabilApiTokenRepository, JabilApiTokenRepository>();

            services.AddScoped<IUnitOfWork, UnitOfWork>();

            services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
        }
    }
}
